package com.tensquare.search.controller;

import com.tensquare.search.service.SearchService;
import entity.PageResult;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/article")
@CrossOrigin
public class SearchController {
    @Autowired
    private SearchService searchService;
    @GetMapping("/search/{keywords}/{page}/{size}")
    public Result findByTitleLike(@PathVariable String keywords,
                                  @PathVariable int page,
                                  @PathVariable int size){
        Page pageData=searchService.findByTitleLike(keywords,page,size);
        return  new Result(true, StatusCode.OK,"ok",new PageResult<>(
                pageData.getTotalElements(),pageData.getContent()));

    }
}
